<template>
	<view>
		<h1>{{name}}</h1>
	</view>
	<view class="">
		<button @click="changeHello">修改打招呼语</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				name:"缓存暂无数据"
			}
		},
		onLoad() {
			/* 读取name缓存 判断name是否缓存有值 有则赋值给this.name 没有则不做 */
			let storageName=uni.getStorageSync("name");
			if(storageName){
				this.name=storageName
			}else{
				console.log("缓存没有获取name数据")
			}
			/* 刚加载页面 就发送ajax请求 */
			console.log("页面正在加载过程中")
			uni.request({
				url: "https://www.baidu.com",
				method:"GET",
				success: (response) => {
					console.log("请求百度成功",response)
				},
				fail:(error)=>{
					console.log("请求百度失败",error)
				}
			})
		},
		methods: {
			changeHello(){
				uni.request({
					url: "http://localhost:10000/charging_api/order/hello",
					method: "GET",
					success: (res) => {
						this.name=res.data
						console.log("拿到对方响应",this.name)

					}
				})
			}
		}
	}
</script>

<style>

</style>
